package map;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;

public class ForEachDemo {
    public static void main(String[] args) {
        Map<String,Integer> map = new HashMap<>();
        map.put("语文",99);
        map.put("数学",100);
        map.put("英语",70);
        map.put("物理",100);
        System.out.println(map);

        Set<String> keyset = map.keySet();
//        keyset.forEach(new Consumer<String>() {
//            @Override
//            public void accept(String s) {
//                System.out.println(s);
//            }
//        });
        keyset.forEach(s -> System.out.println("key:"+s));
        Collection<Integer> value = map.values();
        value.forEach(v -> System.out.println("value:"+v));
        Set<Map.Entry<String,Integer>> entrySet = map.entrySet();
        entrySet.forEach(s -> System.out.println("key"+s.getKey()+",value:"+s.getValue()));

        map.forEach((k,v)->System.out.println("key:"+k));
        map.forEach((k,v)->System.out.println("value:"+v));
        map.forEach((k,v)->System.out.println("key:"+k+",value:"+v));


    }
}
